package com.alibaba.citrus.ots.price.ability.functions.entity.activity;

import com.alibaba.excel.util.CollectionUtils;
import com.epoch.app.otspricecenter.dto.request.ActivityInfoRequest;
import com.epoch.app.otspricecenter.dto.request.ActivityItemInfoRequest;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author: qiaojiange
 * @create: 2021/11/20
 * @Description 根据主单 ID 对组合货品分组存储
 */
@Data
public class CombinationItemGroupByMainOrderIdStore {
    /**
     * 主单 ID
     */
    private String mainOrderId;
    /**
     * 商品信息存储列表
     */
    private List<ItemInfoEntityStore> itemInfoEntityStoreList;


    public CombinationItemGroupByMainOrderIdStore() {
    }

    public CombinationItemGroupByMainOrderIdStore(String key, List<ActivityInfoRequest> infoRequestList) {
        this.mainOrderId = key;
        if (CollectionUtils.isEmpty(infoRequestList)) {
            return;
        }
        List<ItemInfoEntityStore> itemInfoEntityStoreList = new ArrayList<>();
        infoRequestList.forEach(e -> {
            ActivityItemInfoRequest itemInfoRequest = e.getItemList().get(0);
            ItemInfoEntityStore entityStore = new ItemInfoEntityStore(e.getSubOrderId(), itemInfoRequest.getItemId(), itemInfoRequest.getItemQuantity());
            itemInfoEntityStoreList.add(entityStore);
        });
        this.itemInfoEntityStoreList = itemInfoEntityStoreList;
    }

    /**
     * 获取子单号和子单信息映射
     *
     * @return
     */
    public Map<String, ItemInfoEntityStore> obtainItemInfoEntityMap() {
        return this.getItemInfoEntityStoreList().stream().collect(Collectors.toMap(item -> item.getItemId(), Function.identity()));
    }
}